<?php
namespace jy_aikefu;
defined('BY_JYA') or exit('error');
class worker extends \plugin{
	public function checkadd($merchid=0){
		$worker=pdo_get('jy_aikefu_worker',array('merchid'=>$merchid,'uniacid'=>$_SESSION['uniacid']));
		$merch=pdo_get('jy_merch_user',array('id'=>$merchid,'uniacid'=>$_SESSION['uniacid']));
		if(!$merch){
			exi('该商户不存在！','error');
		}
		if($worker['id']){
			pdo_update('jy_aikefu_worker',array('mid'=>$merch['mid'],'title'=>$merch['merchname'].'[客]','logo'=>trim($merch['logo'])),array('merchid'=>$merchid,'uniacid'=>$_SESSION['uniacid']));
			return $worker['id'];
		}
		$insert=array(
			'uniacid'=>$_SESSION['uniacid'],
			'mid'=>$merch['mid'],
			'title'=>$merch['merchname'].'[客]',
			'logo'=>trim($merch['logo']),
			'merchid'=>$merchid,
			'status'=>1,
			'createtime'=>TIMESTAMP,
		);
		pdo_insert('jy_aikefu_worker',$insert);
		$id=pdo_insertid();
		return $id;
	}
	public function upfee($worker=array(),$isbi=0){
		if(!$isbi){
			model('core/member')->member_credit($worker['mid'],'credit2',$worker['fee'],true,'jy_aikefu','客服奖励');
		}else{
			model('core/member')->member_credit($worker['mid'],'credit3',$worker['fee'],true,'jy_aikefu','客服奖励');
		}
		return true;
	}
	public function setcomment($postdata=array()){
		$data=array(
			'content'=>$postdata['content'],
			'images'=>ijson_encode($postdata['images']),
			'star'=>intval($postdata['star']),
		);
		$comment_id=$this->pdo_getcolumn('comment',array('uniacid'=>$_SESSION['uniacid'],'tcpid'=>intval($postdata['tcpid'])),'id');
		if($comment_id){
			if($postdata['show']==1){
				exi('该评价已生效显示，不可修改！','error','goback');
			}
			$this->pdo_update('comment',$data,array('uniacid'=>$_SESSION['uniacid'],'id'=>$comment_id));
		}else{
			$insert=array(
				'uniacid'=>$_SESSION['uniacid'],
				'mid'=>$_SESSION['uid'],
				'tcpid'=>intval($postdata['tcpid']),
				'createtime'=>TIMESTAMP,
			);
			$data=array_merge($insert,$data);
			$data['workerid']=$postdata['workerid'];
			$this->pdo_insert('comment',$data);
		}
		return true;
	}
}